unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  Figure = class
    x, y : integer;
    procedure Draw; virtual; abstract;
  end;

  Square = class(Figure)
    a : integer;
    procedure Draw; override;
  end;

  Circle = class(Figure)
    R, c : integer;
    constructor Create(newc : integer);
    procedure Draw; override;
  end;

  FixedSquare = class(Square)
    constructor Create (newx, newy, newa : integer);
  end;

  RandomSquare=class(Square)
    constructor Create;
  end;

var
  Form1: TForm1;
  mass : array [0..99] of Figure;
  a, newc, i : integer;

implementation

{$R *.dfm}

{ Square }

procedure Square.Draw;
begin
  Form1.Image1.Canvas.Rectangle(x, y, x+a, y+a);
end;

{ Circle }

constructor Circle.Create(newc: integer);
begin
  randomize;
  R:=Random(100);
  c:=newc;
  x := random(Form1.Image1.Width);
  y := random(Form1.Image1.Height);
end;

procedure Circle.Draw;
begin
  Form1.Image1.Canvas.Brush.Color:=c;
  Form1.Image1.Canvas.Ellipse(x, y, x+R, y+R);
  Form1.Image1.Canvas.Brush.Color:=clWhite;
end;

{ FixedSquare }

constructor FixedSquare.Create(newx, newy, newa: integer);
begin
  x:=newx;
  y:=newy;
  a:=newa;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Enabled:=False;

end;

{ RandomSquare }

constructor RandomSquare.Create;
begin
  randomize;
  x := random(Form1.Image1.Width);
  y := random(Form1.Image1.Height);
  a := random(100);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  for i:=0 to 49 do
  begin
    mass[i]:=Circle.Create(clRed);
  end;

  for i:=50 to 74 do
  begin
    mass[i]:=FixedSquare.Create(10*i, 10*i, 59);
  end;

  for i := 75 to 99 do
  begin
    mass[i]:=RandomSquare.Create;
  end;
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  for i:=0 to 99 do
  begin
    mass[i].Draw;
  end;
end;

end.
